#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n * 2);
    for (int i = 0; i < 2 * n; i++) cin >> a[i];
    map<int, pair<int, int>> mp;
    for (int i = 1; i <= n; i++) mp[i] = { -1,-1 };
    for (int i = 0; i < 2 * n; i++)
    {
        if (mp[a[i]].first == -1) mp[a[i]].first = i;
        else if (mp[a[i]].second == -1) mp[a[i]].second = i;
    }
    int ans = 0;
    for (auto [x, y] : mp) ans += y.second - y.first - 1;
    int l = inf, r = -1;
    for (auto [x, y] : mp)
    {
        l = min(l, y.second);
        r = max(r, y.first);
    }
    if (l < r) ans += 2 * (r - l);
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}